home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.04 Apr 88 / TearOffPalette Source / Error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-09  |  2.5 KB  |  114 lines  |  [TEXT/KAHL]

  1. /*
  2. ----------------------------------------------------------------------------------------------------
  3. T E A R O F F   P A L E T T E
  4.  
  5.     version 1.0
  6.     by Don Melton and Mike Ritter
  7.     
  8.     Copyright (C)1987, 1988 by Impulse Technologies, Inc., all rights reserved. 
  9.     
  10.     Filename:            Error.c
  11.     Font:                    Monaco, 9 point
  12.     Tab setting:    2
  13.     Compiler:            LightspeedC 2.15, Project type: APPL, Creator: TOPD
  14.     Segment:            Main */
  15.  
  16.  
  17.  
  18. /*
  19. ----------------------------------------------------------------------------------------------------
  20. GLOBAL CONSTANT DEFINITIONS AND VARIABLE DECLARATIONS */
  21.  
  22. #include "Constants.h"
  23. #include "Variables.h"
  24.  
  25. /*
  26. ----------------------------------------------------------------------------------------------------
  27. EXTERNAL FUNCTION DECLARATIONS */
  28.  
  29. /* None */
  30.  
  31. /*
  32. ----------------------------------------------------------------------------------------------------
  33. FORWARD FUNCTION DECLARATIONS */
  34.  
  35. short GoodNewPtr();
  36. short GoodNewHandle();
  37. short GoodResource();
  38. pascal long RecoverMemory();
  39.  
  40.  
  41.  
  42. /*
  43. ----------------------------------------------------------------------------------------------------
  44. GOOD NEW POINTER */
  45.  
  46. short GoodNewPtr(whichPtr)
  47. Ptr whichPtr;
  48. {
  49.     if((whichPtr != nil) && (MemErr == noErr)) {
  50.         return(true);
  51.     }
  52.     return(false);
  53. }
  54.  
  55. /*
  56. ----------------------------------------------------------------------------------------------------
  57. GOOD NEW HANDLE */
  58.  
  59. short GoodNewHandle(whichHandle)
  60. Handle whichHandle;
  61. {
  62.     if(whichHandle != nil) {
  63.         return(GoodNewPtr(*whichHandle));
  64.     }
  65.     return(false);
  66. }
  67.  
  68.  
  69. /*
  70. ----------------------------------------------------------------------------------------------------
  71. GOOD RESOURCE */
  72.  
  73. short GoodResource(whichHandle)
  74. Handle whichHandle;
  75. {
  76.     if((whichHandle != nil) && (ResError() == noErr)) {
  77.     
  78.         if(*whichHandle != nil) {
  79.             return(true);
  80.         }
  81.     }
  82.     return(false);
  83. }
  84.  
  85.  
  86. /*
  87. ----------------------------------------------------------------------------------------------------
  88. RECOVER MEMORY
  89.  
  90.     RecoverMemory() is a very simple grow zone function designed to prevent the ROM or resident
  91.     software such as desk accessories from generating out of memory errors. After this function is
  92.     called, the application will quit before processing the next event.
  93.     
  94.     See 'Inside Macintosh Volume II,' pages 42-43, about setting up grow zone functions. */
  95.  
  96. pascal long RecoverMemory(memoryNeeded)
  97. Size memoryNeeded;
  98. {
  99.     long bufferSize;
  100.     
  101.     SetUpA5();
  102.     
  103.     bufferSize = GetHandleSize(MemoryBuffer);
  104.     
  105.     if(bufferSize != 0) {
  106.         DisposHandle(MemoryBuffer);
  107.     }
  108.     OutOfMemory = true;
  109.     
  110.     RestoreA5();
  111.     
  112.     return(bufferSize);
  113. }
  114.